package com.bmps.springcloud.insuredmicroservice.model.cloudplatform;

import com.bmps.springcloud.insuredmicroservice.util.cloudplatform.BusinessException;


/**
 * 渠道映射
 * @author llz
 * @date 2019/08/16
 */
public enum ChannelEnum {
    /**
     * 在线网销渠道
     */
    onlineSales(10,3,"网销渠道");
    /**
     *  销售渠道
     */
    private int onlineChanl;
    /**
     *  销售渠道对应的Code
     */
    private int cloudChanl;
    /**
     *  描述
     */
    private String desc;

    private ChannelEnum(int onlineChanl, int cloudChanl, String desc){
        this.onlineChanl = onlineChanl;
        this.cloudChanl = cloudChanl;
        this.desc = desc;
    }

    public int getOnlineChanl() {
        return onlineChanl;
    }

    public void setOnlineChanl(int onlineChanl) {
        this.onlineChanl = onlineChanl;
    }

    public int getCloudChanl() {
        return cloudChanl;
    }

    public void setCloudChanl(int cloudChanl) {
        this.cloudChanl = cloudChanl;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static boolean contains(int onlineChanl) {
        ChannelEnum[] all = values();
        for (ChannelEnum channel : all) {
            if (channel.getOnlineChanl() == onlineChanl) {
                return true;
            }
        }
        return false;
    }

    public static int getCloudChanlByOnlineChanl(int onlineChanl) {
        ChannelEnum[] all = values();
        for (ChannelEnum channel : all) {
            if (channel.onlineChanl == (onlineChanl)) {
                return channel.cloudChanl;
            }
        }
        return -1;
    }

    public static String getDescByOnlineChanl(int onlineChanl) {
        ChannelEnum[] all = values();
        for (ChannelEnum channel : all) {
            if (channel.onlineChanl == (onlineChanl)) {
                return channel.desc;
            }
        }
        throw new BusinessException("找不到 onlineChanl:【{" + onlineChanl + "}】值对应的“Desc”");
    }

    public static int getOnlineChanlByCloudChanl(int cloudChanl) {
        ChannelEnum[] all = values();
        for (ChannelEnum channel : all) {
            if (channel.onlineChanl == (cloudChanl)) {
                return channel.cloudChanl;
            }
        }
        throw new BusinessException("找不到 cloudChanl:【{" + cloudChanl + "}】值对应的“OnlineChanl”");
    }

}
